import server from '../../server/api'
import { Indicator } from 'mint-ui';
// 获取搜索商品列表
const getGoodsListAsyn = ({
	commit,
	state
}, options) => {
	server.post("/index/goods/query", options, function(res) {
		commit('getSearchGoodsListSync', res.data)
	})
}
// 获取首页商品数据
const getIndexDataAsyn = ({
	commit,
	state
}) => {
	Indicator.open({
		text: '加载中...',
		spinnerType: 'fading-circle'
	});
	server.post('/index/goods/goods_index', function(res) {
		if(res.error == 0) {
			Indicator.close();
		}
		commit('getIndexGoodsSync', res.data)
	})
}
// 获取首页分类列表数据
const getIndexClassifyAsyn = ({
	commit,
	state
}) => {
	server.post('/index/goods/gooods_typew', function(res) {
		commit('getIndexClassifySync', res.data)
	})
}
const getClassifyGoodsDataAsyn = ({
	commit,
	state
}, options) => {
	server.post('/index/goods/typeInfo', options, function(res) {
		commit('getClassifyGoodsDataSync', res.data)
	})
}
// 设置拼团 成员头像
const getShareMemberInfo = ({
	commit,
	state
}, options) => {
	if(options.type == "share") {
		const shareParam = {
			cantuanid: options.cantuanid
		}
		server.post('/index/chat/groupInfo', shareParam, function(res) {
			commit('setShareMemberInfo', res.data)
		})
	}
}
export default {
	getGoodsListAsyn,
	getIndexDataAsyn,
	getIndexClassifyAsyn,
	getClassifyGoodsDataAsyn,
	getShareMemberInfo
}